<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline"  @keyup.enter.native="searchQuery">
        <a-row :gutter="12">
          <a-col :md="6" :sm="8">
            <a-form-item label="" :labelCol="{ span: 6 }" :wrapperCol="{ span: 14, offset: 0 }">
              <a-input placeholder="活动名称" v-model="queryParam.activityName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>

      <div class="table-operator" style="border-top: 5px">
        <a-button type="primary" @click="handleAdd">新增</a-button>
      </div>

      <a-table
        ref="table"
        rowKey="id"
        size="middle"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">
        <span slot="activityTemplId" slot-scope="text, record">
          {{record.activityTemplId == -1 ? '' : record.activityTemplId}}
        </span>
        <span slot="subscribeTemplId" slot-scope="text, record">
          {{record.subscribeTemplId == -1 ? '' : record.subscribeTemplId}}
        </span>
        <span slot="activityTime" slot-scope="text, record">
          {{record.activityDate}}/{{record.activityTime}}
        </span>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">
            <a-icon type="edit"/>
            编辑
          </a>
          <a-divider type="vertical"/>
          <a-popconfirm title="确定删除吗?" @confirm="() =>handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
          <a-divider type="vertical"/>
          <a-button @click="handlerqEdit(record,1)" type="link" :disabled="record.whiteListStatus == 0">白名单</a-button>
          <a-button @click="msgSendEdit(record)" type="link" :disabled="record.whiteListStatus == 0">短信通知</a-button>
          <a-button @click="msgLogEdit(record,1)" type="link" >短信通知记录</a-button>
          <a-divider type="vertical"/>
          <a-button @click="handlerqEdit(record,2)" type="link" >微信推送名单</a-button>
          <a-button @click="wxSendEdit(record)" type="link">微信消息推送</a-button>
          <a-button @click="msgLogEdit(record,2)" type="link">微信消息推送记录</a-button>
        </span>
      </a-table>
    </div>

    <push-Modal ref="modalForm" @ok="modalFormOk"></push-Modal> 
    <rq-Modal ref="rqmodalForm" @ok="modalFormOk"></rq-Modal> 
    <msg-Modal ref="msgmodalForm" @ok="modalFormOk"></msg-Modal> 
  </a-card>
</template>

<script>
import { filterObj } from '@/utils/util';
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { sendSms, sendTemplateMsg } from '@/api/marketingCenter/invite'
import pushModal from './modules/pushModal'
import rqModal from './modules/rqModal'
import msgModal from './modules/msgModal'

export default {
  name:'',
  mixins:[JeecgListMixin],
  components: { 
    pushModal,
    rqModal,
    msgModal,
  },
  data() {
    return {
      queryParam:{
        current: 1,
        size: 10,
      },
      // 禁止重复点击
      msgdisable: true,
      wxdisable: true,
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 120,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '名称',
          align: "center",
          dataIndex: 'activityName',
        },
        {
          title: '场次时间',
          align: "center",
          dataIndex: 'activityTime',
          scopedSlots: {customRender: 'activityTime'},
        },
        {
          title: '活动消息模板ID',
          align: 'center',
          // dataIndex: 'activityTemplId',
          scopedSlots: {customRender: 'activityTemplId'},
        },
        {
          title: '订阅消息模板ID',
          align: 'center',
          // dataIndex: 'subscribeTemplId',
          scopedSlots: {customRender: 'subscribeTemplId'},
        },
        {
          title: '订阅消息微信模板ID',
          align: 'center',
          dataIndex: 'subscribeWxTemplId',
        },
        {
          title: '白名单开关',
          align: 'center',
          dataIndex: 'whiteListStatusText',
        },
        {
          title: '操作',
          align: "center",
          dataIndex: 'action',
          scopedSlots: {customRender: 'action'},
        },
      ],
      url: {
        list: "/backend/invitation/pagePushVo",
        delete: "/backend/invitation/delPushById",
      },
    }
  },
  created() {},
  methods: {
    getQueryParams() {
      var param = Object.assign({}, this.queryParam);
      param.current = this.ipagination.current;
      param.size = this.ipagination.pageSize;
      return filterObj(param);
    },
    handlerqEdit(record,type) {
      console.log(type,'--type');
      this.$refs.rqmodalForm.edit(record,type);
      if (type == 1) {
        this.$refs.rqmodalForm.title = "白名单";
      } else if (type == 2) {
        this.$refs.rqmodalForm.title = "微信推送名单";
      }
      this.$refs.rqmodalForm.disableSubmit = false;
    },
    msgSendEdit(record) {
      if (this.msgdisable){
        this.msgdisable = false
        sendSms({pushId:record.id}).then(res => {
          this.msgdisable = true
          if (res.code == 200) {
            this.$message.success(res.msg)
          } else {
            this.$message.error(res.msg)
          }
        })
      }
    },
    wxSendEdit(record) {
      if (this.wxdisable){
        this.wxdisable = false
        sendTemplateMsg({pushId:record.id}).then(res => {
          this.wxdisable = true
          if (res.code == 200) {
            this.$message.success(res.msg)
          } else {
            this.$message.error(res.msg)
          }
        })
      }
    },
    msgLogEdit(record,type) {
      this.$refs.msgmodalForm.edit(record,type);
      if (type == 1) {
        this.$refs.msgmodalForm.title = "短信通知记录";
      } else if (type == 2) {
        this.$refs.msgmodalForm.title = "微信消息推送记录";
      }
      this.$refs.msgmodalForm.disableSubmit = false;
    },
  }
}
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>